package com.heima.controller;

import com.heima.pojo.User;
import com.heima.pojo.dto.NodeDto;
import com.heima.pojo.dto.RegionInfoPageDto;
import com.heima.pojo.dto.UserDto;
import com.heima.pojo.vo.NodeCountVo;
import com.heima.pojo.vo.NodePageVo;
import com.heima.pojo.vo.VendingMachineVo;
import com.heima.service.NodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@Api(tags = "点位接口")
@RequestMapping("/api/vm-service/node")
public class NodeController {

    @Autowired
    private NodeService nodeService;

    /**
     * 查询区域详情
     */
    @GetMapping("/search")
    @ApiOperation("查询区域详情")
    public NodePageVo queryRegionInfo(RegionInfoPageDto dto){
        log.info("dto:{}",dto);
        return nodeService.queryRegionInfo(dto);
    }

    /**
     * 新增点位
     */
    @PostMapping
    @ApiOperation("新增点位")
    public Boolean add(@RequestBody NodeDto dto){
        log.info("dto:{}",dto);
        nodeService.save(dto);
        return true;
    }

    /**
     * 查询点位详情
     */
    @GetMapping("/vmList/{nodeId}")
    @ApiOperation("查询点位详情")
    public List<VendingMachineVo> getDetailednode(@PathVariable String nodeId){
        log.info("id:{}",nodeId);
        List<VendingMachineVo> vos = nodeService.getDetailedNode(nodeId);
        return vos;
    }

    /**
     * 修改点位
     */
    @ApiOperation("修改点位")
    @PutMapping("/{nodeId}")
    public Boolean update(@PathVariable String nodeId,@RequestBody NodeDto dto){
        log.info("id:{},dto:{}",nodeId,dto);
        dto.setId(Long.parseLong(nodeId));
        nodeService.save(dto);
        return true;
    }

    /**
     * 删除点位
     */
    @DeleteMapping("/count/{nodeId}")
    @ApiOperation("删除点位")
    public Boolean deleteById(@PathVariable String nodeId){
        log.info("id:{}",nodeId);
        nodeService.deleteById(nodeId);
        return true;
    }

    /**
     * 点位数量
     */
    @GetMapping("/{userId}")
    @ApiOperation("点位数量查询")
    public Integer count(){
        log.info("查询点位数量");
        Integer count = nodeService.count();
        return count;
    }

    /**
     *合作商点位汇总统计
     */
    @GetMapping("/nodeCollect")
    public List<NodeCountVo> nodeCount(){

        return nodeService.nodeCount();
    }

}
